'''练习：Fibonacci迭代器'''


class Fibonacci():

    def __init__(self,n):
        self.n = n

    def __repr__(self):
        return "Fibonacci(%d)"%self.n

    def __iter__(self):
        return Myiter(self.n)


class Myiter():
    def __init__(self,n):
        self.stop = n
        self.n=1
        # 方法1
        # self.l = [0,1]

        #方法2
        self.a =0
        self.b =1

    def __next__(self):
        # 方法2
        if self.n <= self.stop:
            index = self.a
            self.a,self.b = self.b,self.a+self.b
            self.n += 1
            return index
        else:
            return 'over'



        #方法一
        # if self.n <= self.stop:
        #     if self.n >= 3:
        #         f = self.l[self.n - 2] + self.l[self.n - 3]
        #         self.l.append(f)
        #         self.n+=1
        #         return self.l[self.n-2]
        #     else:
        #         self.n+=1
        #         return self.l[self.n-2]
        # else:
        #     print('输入错误')


n = 10
fibonacci = Fibonacci(n)
it = iter(fibonacci)
for i in range(n):
    print(next(it))